package com.yjhb.android.sbz.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.RefreshPackage;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;

/**
 * 创建者 zx
 * 创建时间 2020/12/7 10:20
 */
public class RefreshPackageAdapter extends BaseRecyclerAdapter<RefreshPackageAdapter.RefreshPackageHolder, RefreshPackage> {
    private final String TAG = "RefreshPackageAdapter";

    private int selectedIndex = 0;

    public RefreshPackageAdapter(Context context) {
        super(context);
    }

    @Override
    protected RefreshPackageHolder getHolder(View v) {
        return new RefreshPackageHolder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_refresh_package;
    }

    @Override
    public void onBindViewHolder(@NonNull RefreshPackageHolder refreshPackageHolder, int i) {
        try {
            if (selectedIndex == i) {
                refreshPackageHolder.layout_item.setSelected(true);
            } else {
                refreshPackageHolder.layout_item.setSelected(false);
            }
            refreshPackageHolder.num_tv.setText(entity.getNum() + "次");
            refreshPackageHolder.money_tv.setText("￥" + entity.getMoney() + "元");

        } catch (Exception er) {
        }
    }

    public int getSelectedIndex() {
        return selectedIndex;
    }

    public void setSelectedIndex(int selectedIndex) {
        this.selectedIndex = selectedIndex;
    }

    class RefreshPackageHolder extends RecyclerView.ViewHolder {
        TextView money_tv;
        TextView num_tv;
        View layout_item;

        public RefreshPackageHolder(@NonNull View itemView) {
            super(itemView);
            num_tv = itemView.findViewById(R.id.num_tv);
            money_tv = itemView.findViewById(R.id.money_tv);
            layout_item = itemView.findViewById(R.id.layout_item);
        }
    }


}
